package com.tanhua.server.controlle;

import com.tanhua.common.utils.Cache;
import com.tanhua.common.utils.UserThreadLocal;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.server.service.TodayBestService;

import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ly
 * @Date: 2021/07/29/20:54
 * @Description:
 */
@RestController
@RequestMapping("tanhua")
@Slf4j
public class TodayBestController {

    @Autowired
    private TodayBestService todayBestService;



    /*
    * 查询今日佳人
    * */
    @GetMapping("todayBest")
    public ResponseEntity<RecommendUser>  queryTodayBest(){

        TodayBest todayBest = todayBestService.queryTodayBest();

        try {
            //成功查询到佳人
            if (todayBest!=null){
                ResponseEntity.ok(todayBest);
            }
        } catch (Exception e) {
            log.error("查询今日佳人失败  UserId="+ UserThreadLocal.get().getId(),e);
           // e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }




    /**
     * 查询推荐用户列表
     *
     * @param
     * @param queryParam
     * @return
     */
    @GetMapping("recommendation")
    @Cache(time = "30")
    public  ResponseEntity<PageResult> queryRecommendation(
                                                           RecommendUserQueryParam  queryParam){
        try {
            PageResult pageResult = todayBestService.queryRecommendation( queryParam);
            if (pageResult!=null){
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询列表失败 UserId"+UserThreadLocal.get().getId(),e);
           // e.printStackTrace();
        }
        return  ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
